Clean code, fix bug, refactor a little. Related to #647 and #584