[#905] Sort imports correctly, improve PEP8, remove unused code