Refactored a bit and added options functionality