Cleaned up code as per acantino's reccommendations