cleaned up code and added more type returns