Fixed issues, made sure this is a pretty DRY implementation