small fixes and cleaner code