cleaned up code made smaller