Cleaned code, thanks to @bebraw