Further refactoring. Added brackets, small bug fix