Added options and restructured part of the code