Small bug fixes, cleaned code