Cleaned up code and separated out js