Sometimes in those situations you even have to put down your guitar, and listen to how it goes in your head, where it's all perfect. Try to guess where it would be on the guitar before you even pick it up, then actually try it on the guitar.
That's what I always do. Whenever I come up with a string of riffs that work together they kinda tell me where they belong in the grand scheme of a song which helps me figure out what belongs before and after them.