Cleaned up some logic