Putted evertything in a main() function to get better performance