Bugfixes and cleanups
@temas, there are some TODO Temas's