split code into sub files
added rotation logic