Cleaned up code and changed some behaviour