Cleaned up the initial code, ready to expand the functionality