Cleaned up code to make it more compact.