cleaner code and fixed some small issues