added type, cleaned up code a bit